<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Gets default parameter value</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="reflectionparameter.getdeclaringfunction.html">ReflectionParameter::getDeclaringFunction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="reflectionparameter.getdefaultvalueconstantname.html">ReflectionParameter::getDefaultValueConstantName</a></div>
 <div class="up"><a href="class.reflectionparameter.html">ReflectionParameter</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="reflectionparameter.getdefaultvalue" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionParameter::getDefaultValue</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.0.3)</p><p class="refpurpose"><span class="refname">ReflectionParameter::getDefaultValue</span> &mdash; <span class="dc-title">Gets default parameter value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionparameter.getdefaultvalue-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>ReflectionParameter::getDefaultValue</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="para rdfs-comment">
   Gets the default value of the parameter for a user-defined function or method.
   If the parameter is not optional a <a href="class.reflectionexception.html" class="classname">ReflectionException</a>
   will be thrown.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionparameter.getdefaultvalue-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionparameter.getdefaultvalue-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The parameters default value.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-reflectionparameter.getdefaultvalue-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5141">
    <p><strong>Example #1 Getting </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">$test</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'baz'</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$function&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$function</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParameters</span><span style="color: #007700">()&nbsp;as&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Name:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isOptional</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Default&nbsp;value:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDefaultValue</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Name: test

Name: bar
Default value: baz
</pre></div>
   </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-reflectionparameter.getdefaultvalue-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Due to implementation details, it is not possible to get the default value
    of built-in functions or methods of built-in classes. Trying to do this will
    result a <a href="class.reflectionexception.html" class="classname">ReflectionException</a> being thrown.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionparameter.getdefaultvalue-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="reflectionparameter.isoptional.html" class="methodname" rel="rdfs-seeAlso">ReflectionParameter::isOptional()</a> - Checks if optional</span></li>
    <li class="member"><span class="methodname"><a href="reflectionparameter.ispassedbyreference.html" class="methodname" rel="rdfs-seeAlso">ReflectionParameter::isPassedByReference()</a> - Checks if passed by reference</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="reflectionparameter.getdeclaringfunction.html">ReflectionParameter::getDeclaringFunction</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="reflectionparameter.getdefaultvalueconstantname.html">ReflectionParameter::getDefaultValueConstantName</a></div>
 <div class="up"><a href="class.reflectionparameter.html">ReflectionParameter</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
